package com.example.mobile2121606109ycg0407;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivityTip4 extends AppCompatActivity {

    private EditText edtTxtMain4Num;
    private TextView tvMain4Result;
    private Button btnMain4Result;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_tip4);
        initView();

        btnMain4Result.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //获取数值的华氏温度
                double HS = Double.parseDouble(edtTxtMain4Num.getText().toString());
                //华氏温度转化为华氏温度
                double SS = 5*(HS - 32)/9;
                //输出结果并保留两位小数
                tvMain4Result.setText(String.format("%.2f", SS));
            }
        });
    }

    private void initView() {
        edtTxtMain4Num = (EditText) findViewById(R.id.edtTxtMain4_Num);
        tvMain4Result = (TextView) findViewById(R.id.tvMain4_Result);
        btnMain4Result = (Button) findViewById(R.id.btnMain4_Result);
    }
}